<?php

class moduleGroupModel extends CDBModelBase
{	
	public function getTabelName(){
		return "tbl_base_module_group";
	}

	public function getPKID(){
		return "module_group_id";
	}
	
	protected function getSequence()
	{
		return "MODULE_SEQUENCE";
	}
	

	/**
	 * 插入
	 * @param array $p
	 */
	public function add($p=array())
	{

		$sql = "SELECT MAX(sort_num) FROM tbl_base_module_group";
		
		$sort_num = $this->db->executeScalar($sql);
		
		if($sort_num===false){
			$sort_num = 0;
		}
		else
		{
			$sort_num ++ ;
		}
		
		$p["sort_num"] = $sort_num;
		
		return $this->insert($p);
	}
	
	
	/**
	 * 查询出所有
	 */
	public function selectAll()
	{
		return $this->db->executeDataSet("SELECT
			module_group_id,
			group_name,
			group_level,
			del_flag,
			create_time,
			update_time,
			sort_num
		FROM
			tbl_base_module_group 
		WHERE del_flag=0
		ORDER BY sort_num, module_group_id");
	}
	
}